﻿using CPPEI.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using SER = CPPEI.ETL.Domain.Services;
using ENT = CPPEI.ETL.Domain.Entities;
using MOD = CPPEI.ETL.Domain.Models;
using CPPEI.ETL.Domain;

namespace CPPEI.ETL.WebApi
{
    /// <summary>
    /// 将第三方数据表转换为系统内部的数据表
    /// </summary>
    [CPPEI.WebApi.AuthPostAction("TPT", "Convert", "1.0")]
    public class ConvertAction : BaseAction<ConvertParams, ConvertResult>
    {
        protected override ActionResult<ConvertResult> OnExecute(ActionContext context,
            SysParameters sysParameters,
            ConvertParams opParams)
        {
            ConvertResult result = new ConvertResult();

            ServiceResult<ENT.EDtTable> serResult = new SER.DtTableService().ConvertToDtTable(opParams.TableId);
            if (serResult.IsSuccess)
            {
                ConvertResult actResult = new ConvertResult();
                actResult.DataTableId = serResult.Data.Id;
                return new ActionResult<ConvertResult>(actResult);
            }
            else
            {
                return new ActionResult<ConvertResult>(serResult.IsSuccess, serResult.ErrorCode, serResult.Message, null);
            }
        }
    }

    public class ConvertParams
    {
        /// <summary>
        /// 第三方数据表id
        /// </summary>
        public int TableId { get; set; }
    }

    public class ConvertResult
    {
        /// <summary>
        /// 数据表id
        /// </summary>
        public Guid DataTableId { get; set; }
    }
}
